stone = gr.material({72/255.0, 61/255.0, 139/255.0}, {0.3, 0.3, 0.3}, 20)
green = gr.material({0.1, 0.7, 0.1}, {0.3, 0.3, 0.3}, 20)
purple = gr.material({0.7, 0.6, 1.0}, {0.5, 0.4, 0.8}, 25)
transparent = gr.material({0, 0, 1.0}, {0.3, 0.3, 0.3}, 20,0,2.0)
floor_mat = gr.material({0.5, 0.5, 0.5}, {0.3, 0.3, 0.3}, 20,0.3)


gold = gr.material({0.9, 0.8, 0.4}, {0.8, 0.8, 0.8}, 25,0.6)
--silver = gr.material({205/255.0, 201/255.0, 201/255.0}, {0.3, 0.3, 0.3}, 20,0.5)
silver = gr.material({0.2, 0.2, 0.2}, {0.3, 0.3, 0.3}, 20,0.6)
floor = gr.texture("floor1.png")
wall = gr.bump("wall-normal-map.png")
tshirt = gr.texture("tshirt.png")

scene = gr.node('scene')
scene:translate(185, 170, -120)
--scene:translate(155, 170, -300)

s1 = gr.sphere('s1')
s1:set_material(gold)
s1:scale(20, 20, 20)

s2 = gr.sphere('s2')
s2:set_material(gold)
s2:scale(19, 19, 19)

c1 = gr.cube('c1')
c1:set_material(gold)
c1:scale(40,40,40)
c1:translate(-0.5,0,-0.5)

cup1 = gr.csg('cup1',3,gr.csg('',3,s1,c1),s2)
cup1:scale(4.5,5.5,4.5)
cup1:translate(0,22,0)

-------------------- cup top

cy1 = gr.cylinder('cy1',5,5)
cy1:set_material(gold)
cy1:scale(9,5,9)
cy1:translate(0,-15,0)

t1 = gr.torus('t1',6,33)
t1:set_material(gold)
t1:translate(0,-48,0)
t1:rotate('x',90)
bottom1 = gr.csg('bottom1',1,cy1,t1)

t2 = gr.torus('t2',6,29)
t2:set_material(gold)
t2:translate(0,-43,0)
t2:rotate('x',90)
bottom2 = gr.csg('bottom2',1,bottom1,t2)

t3 = gr.torus('t3',6,25)
t3:set_material(gold)
t3:translate(0,-38,0)
t3:rotate('x',90)
bottom3 = gr.csg('bottom3',1,bottom2,t3)

t4 = gr.torus('t4',6,21)
t4:set_material(gold)
t4:translate(0,-33,0)
t4:rotate('x',90)
bottom4 = gr.csg('bottom4',1,bottom3,t4)

cy2 = gr.cylinder('cy2',5,5)
cy2:set_material(gold)
cy2:scale(4,4,4)
cy2:translate(0,-8,0)
bottom5 = gr.csg('bottom5',1,bottom4,cy2)

s3 = gr.sphere('s3')
s3:set_material(transparent)
s3:scale(30, 30, 30)
s3:translate(0,0.1,0)
bottom6 = gr.csg('bottom6',1,bottom5,s3)

t5 = gr.torus('t5',7,19)
t5:set_material(gold)
t5:translate(0,-16,0)
t5:rotate('x',90)
bottom7 = gr.csg('bottom6',1,bottom6,t5)

t6 = gr.torus('t6',7,19)
t6:set_material(gold)
t6:translate(0,20,0)
t6:rotate('x',90)
bottom8 = gr.csg('bottom7',1,bottom7,t6)

s4 = gr.sphere('s4')
s4:set_material(gold)
s4:scale(25, 20, 25)
s4:translate(0,2,0)
bottom9 = gr.csg('bottom9',1,bottom8,s4)

cy2 = gr.cylinder('cy2',3,3)
cy2:set_material(gold)
cy2:scale(8,8,8)
cy2:translate(0,5,0)

bottom10 = gr.csg('bottom10',3,bottom9,cy2)
bottom10:translate(0,-30,0)
cup = gr.csg('cup', 1, bottom10, cup1)
cup:scale(0.18,0.18,0.18)
cup:translate(-860,-972,220)
--scene:add_child(cup)

base = gr.nh_box('base', {0, 0, -10}, 30)
--scene:add_child(base)
base:set_material(silver)
base:translate(-177.5,-197,30)
base:scale(1.5, 0.1, 1.5)

top = gr.nh_box('top', {0, 0, -10}, 30)
--scene:add_child(top)
top:set_material(silver)
top:translate(-177.5,-147,30)
top:scale(1.5, 0.1, 1.5)

side1 = gr.cylinder('side1',3, 50)
side1:set_material(transparent)
side1:translate(-173,-195,55)
--scene:add_child(side1)

side2 = gr.cylinder('side2',3, 50)
side2:set_material(transparent)
side2:translate(-137,-195,55)
--scene:add_child(side2)

side3 = gr.cylinder('side3',3, 50)
side3:set_material(transparent)
side3:translate(-173,-195,20)
--scene:add_child(side3)

side4 = gr.cylinder('side4',3, 50)
side4:set_material(transparent)
side4:translate(-137,-195,20)
--scene:add_child(side4)

finished_cup = gr.node('finecup')
finished_cup:add_child(side1)
finished_cup:add_child(side2)
finished_cup:add_child(side3)
finished_cup:add_child(side4)
finished_cup:add_child(base)
finished_cup:add_child(top)
finished_cup:add_child(cup)
finished_cup:translate(-25,0,0)

scene:add_child(finished_cup)
-- puppet
require('puppet')
scene:add_child(puppet)
puppet:translate(-190, -183, 40.0)
puppet:scale(1.6,1.6,1.6)
puppet:rotate('y',90)
puppet:rotate('x',15)
Joint_LeftUpperArm:rotate('x',-110)
Joint_RightUpperArm:rotate('x',-110)
Joint_LeftForeArm:rotate('x',-20)
Joint_RightForeArm:rotate('x',-20)
Joint_LeftThigh:rotate('x',-55)
Joint_RightThigh:rotate('x',30)
Joint_LeftCalf:rotate('x',50)
Joint_Head:rotate('x',-20)
Joint_LeftFoot:rotate('x',-10)

pic = gr.nh_box('pic', {0, 0, -10}, 20)
pic:set_material(green)
pic:translate(-240,-190,0)
pic:scale(2,3,0.1)
--pic:rotate('z',15)
pic:set_texture(tshirt)
scene:add_child(pic)

--########################################## house
plane_buttom = gr.nh_box('plane_buttom', {0, 0, -10}, 30)
scene:add_child(plane_buttom)
plane_buttom:set_material(floor_mat)
plane_buttom:translate(-250,-200,0)
plane_buttom:scale(6, 0.1, 4.5)
plane_buttom:set_texture(floor)

plane_back = gr.nh_box('plane_back', {0, 0, -10}, 30)
plane_back:set_material(stone)
plane_back:set_bump(wall)
plane_back:translate(-250,-200,-20)
plane_back:scale(6, 4, 1)
scene:add_child(plane_back)

plane_left = gr.nh_box('plane_left', {0, 0, -10}, 30)
scene:add_child(plane_left)
plane_left:set_material(stone)
plane_left:set_bump(wall)
plane_left:translate(-250,-200,-10)
plane_left:scale(0.1, 4, 4)
plane_left:rotate('z',90)

plane_right = gr.nh_box('plane_right', {0, 0, -10}, 30)
scene:add_child(plane_right)
plane_right:set_material(stone)
plane_left:set_bump(wall)
plane_right:translate(-70,-200,-10)
plane_right:scale(0.1, 4, 4)
plane_right:rotate('z',90)

-- The lights
l1 = gr.light(5,3,{200,200,400}, {0.7, 0.7, 0.7}, {1, 0, 0})

gr.render(scene, 'finalscene.png', 500, 500, 
	  {0, 0, 0,}, {0, 0, -1}, {0, 1, 0}, 50,
	  {0.4, 0.4, 0.4}, {l1},1,0,0,0,0,0)